package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/4/16 13:31
 * https://leetcode-cn.com/problems/number-of-provinces/
 */
public class Title547 {

    int count;
    int n, m;

    /**
     * 相连的看成一个，不相连的看成一个
     * @param isConnected
     * @return
     */
    public int findCircleNum(int[][] isConnected) {
        n = isConnected.length;
        m = isConnected[0].length;
        count = 0;
        //从每个点都出发
        for (int i = 0; i < n; i++) {
            if (isConnected[i][0] != -1) {
                count++;
                dfs(isConnected, i);
            }
        }
        return count;
    }

    private void dfs(int[][] isConnected, int cur) {
        if (isConnected[cur][0] == -1) {
            return;
        }
        isConnected[cur][0] = -1;
        for (int i = 1; i < isConnected[cur].length; i++) {
            if (isConnected[cur][i] == 1) {
                dfs(isConnected, i);
            }
        }
    }

    public static void main(String[] args) {

    }
}
